package com.his.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.his.bean.DzmHisMember;
import com.his.bean.SysMenu;
import com.his.service.DzmHisMemberService;
import com.his.mapper.DzmHisMemberMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 */
@Service
public class DzmHisMemberServiceImpl extends ServiceImpl<DzmHisMemberMapper, DzmHisMember>
        implements DzmHisMemberService{

    @Autowired
    DzmHisMemberMapper dzmHisMemberMapper;

    @Override
    public DzmHisMember getUserNameAndPassWord(String username, String strpassword) {
        DzmHisMember dzmHisMember = dzmHisMemberMapper.getUserNameAndPassWord(username,strpassword);
        return dzmHisMember;
    }

    @Override
    public int updatePwd(String uid) {
        return dzmHisMemberMapper.updatePwd(uid);
    }

    @Override
    public int jinyong(String uid) {
        return dzmHisMemberMapper.jinyong(uid);
    }

    @Override
    public int qiyong(String uid) {
        return dzmHisMemberMapper.qiyong(uid);
    }

    @Override
    public DzmHisMember memberUid(int id) {
        return dzmHisMemberMapper.memberUid(id);
    }

    @Override
    public List<Map> getRouters(String uid) {


        List<SysMenu> routers = dzmHisMemberMapper.getRouters(uid);
        List<Map> listMap = new ArrayList<>();
        System.out.println(routers);

        for(int i = 0; i < routers.size(); i++){
            // 如果等于0 证明是一级菜单
            if(routers.get(i).getParentId() == 0) {
//                System.out.println("1");
                // 用来装每一个路由
                Map map = new HashMap();
                //用来了装路由名称和图标
                Map titleAndIcon = new HashMap();
                //用来装每一路由里面的子路由
                List<Map> childrenMap = new ArrayList<>();
                map.put("path",routers.get(i).getPath());
                map.put("component",routers.get(i).getComponent());
                titleAndIcon.put("icon",routers.get(i).getIcon());
                titleAndIcon.put("title",routers.get(i).getMenuName());
                map.put("meta",titleAndIcon);



                for (int j = 0; j < routers.size(); j++) {
//                    System.out.println("i:"+routers.get(i).getMenuId()+"j:"+routers.get(j).getParentId());
                    Long numi = routers.get(i).getMenuId();
                    Long numj = routers.get(j).getParentId();
                    if(numi.longValue() == numj.longValue()){
//                        System.out.println("sssssssssssss");
                        //循环添加他的所有路由
                        // 用来装每一个路由
                        Map map2 = new HashMap();
                        //空数组
                        List<Map> childrenMap2 = new ArrayList<>();
                        //用来了装路由名称和图标
                        Map titleAndIcon2 = new HashMap();
                        //用来装每一路由里面的子路由
                        map2.put("path",routers.get(j).getPath());
                        map2.put("component",routers.get(j).getComponent());
                        titleAndIcon2.put("icon",routers.get(j).getIcon());
                        titleAndIcon2.put("title",routers.get(j).getMenuName());
                        map2.put("meta",titleAndIcon2);
                        map2.put("children",childrenMap2);
                        childrenMap.add(map2);
                    }
                }
                map.put("children",childrenMap);
                listMap.add(map);
            }
        }
        return listMap;


    }
}
